package com.jinghong.epidemiccontrolproject.mapper;

import com.jinghong.epidemiccontrolproject.pojo.Patient;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
 * ClassName:PatientMapper
 * Package:com.jinghong.epidemiccontrolproject.mapper
 * Description:
 *
 * @Author: 寻月君子
 * @CreatTime:2024/1/20 15:01
 * Version:1.0
 */
@Mapper
public interface PatientMapper {


    /**
     * 批量删除病患
     *
     * @param ids
     */
    void delete(List<Integer> ids);


    /**
     * 病人信息查询
     *
     * @param name
     * @param gender
     * @param age1
     * @param age2
     * @param regionId
     * @param begin
     * @param end
     * @param status
     * @return
     */
    List<Patient> list(String name, Short gender, Integer age1, Integer age2, Integer regionId, LocalDate begin, LocalDate end, Short status);


    /**
     * 新增员工
     *
     * @param patient
     */
    @Insert("insert into patient( name, gender, age,`id_card_num`,region_id,address,certify_time,update_time,status) " +
            " values(#{name},#{gender},#{age},#{idCardNum},#{regionId},#{address},#{certifyTime},#{updateTime},#{status})")
    void insert(Patient patient);


    /**
     * 根据ID查询员工
     *
     * @param id
     * @return
     */
    @Select("select * from patient where  id = #{id}")
    Patient getById(Integer id);

    /**
     * 批量查询
     * @param ids
     * @return
     */
    List<Patient> get(List<Integer> ids);

    /**
     * 根据ID更新病人数据
     *
     * @param patient
     * @return
     */
    void update(Patient patient);


    /**
     * 对病患的感染情况进行统计(添加,更新,和删除时会调动重新统计)
     * @param
     * @return
     */
    @Select("select count(*) from patient where region_id = #{regionId} and status = #{status}")
    Integer Count(Integer regionId,Short status);

    @Delete("delete from patient where id = #{id}")
    void deleteById(Integer id);
}
